# -*- coding: utf-8 -*-
from flask import session, redirect, request, url_for
from functools import wraps

import qrcode
from StringIO import StringIO   # python 2.x


def logged_in(f):
    @wraps(f)
    def wrapper(*args, **kwargs):
        if 'logged_in' not in session:
            return redirect(url_for('login', next=request.url))
        return f(*args, **kwargs)
    return wrapper


def QRMake(text):
    '''
    :param text:  text to create QR image
    :return: QR image in memory
    '''
    img = qrcode.make(text)
    buf = StringIO()
    img.save(buf, 'PNG')
    buf.seek(0)
    return buf





